﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TravelLink.WebModel;
using TravelLink.DAL;

namespace TravelLink.WebApp.UserControl.Register {
    public partial class UC_Register_Index : ControlBase {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void btnRegisterSubmit_Click(object sender, ImageClickEventArgs e) {
            TL_User newUser = new TL_User();
            newUser.UserCode = Guid.NewGuid();
            newUser.Email = this.txtRegisterUserName.Text;
            newUser.Mobile = this.txtRegisterMobile.Text;
            newUser.Password = this.txtRegisterPassword.Text;
            newUser.CreateDate = DateTime.Now;
            newUser.Status = 0;
            if (UserController.GetInstance().Register(newUser)) {
                Response.Redirect(Consts.Member_RegisterSuccess);
                return;
            }
        }

        protected void btnSubmit_Click(object sender, ImageClickEventArgs e) {
            string error = string.Empty;
            if ((error = UserController.GetInstance().Login(this.txtUserName.Text, this.txtPassword.Text)) == "OK") {

                if (!string.IsNullOrEmpty(WebHelper.GetQueryStringStr("ref"))) {
                    Response.Redirect(WebHelper.GetQueryStringStr("ref"));
                }
                else {
                    Response.Redirect(Consts.Member_Default);
                }


                return;
            }
            else {
                RegisteScript("alert('" + error + "');");
            }
        }
    }
}